package com.chy.order_meal.controller;

import com.chy.order_meal.bean.ChyResponse;
import com.chy.order_meal.dao.GoodsDao;
import com.chy.order_meal.po.GoodsType;
import com.chy.order_meal.po.Type;
import com.chy.order_meal.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/goods/")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @GetMapping("get/{id}")
    @ResponseBody
    public ChyResponse getGoodsByResId(@PathVariable("id") Integer id){
        try{
            List<GoodsType> data = goodsService.getGoodsByResId(id);
            return ChyResponse.simpSuccess(data);
        }catch (Exception e){
            e.printStackTrace();
            return new ChyResponse(false,"商品信息查询失败",null);
        }
    }

}
